package com.ohuang.launcher.smallwindow;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.graphics.PixelFormat;
import android.view.View;
import android.view.WindowManager;
import android.widget.FrameLayout;

public abstract class DialogWindow implements WindowInterface {

    private Activity activity;
    private boolean isShow = false;
    private boolean isInit = false;
    private Dialog dialog;

    public DialogWindow(Activity activity) {
        this.activity = activity;
    }

    @Override
    public boolean isShow() {
        return false;
    }

    @Override
    public void show() {
        if (!isInit) {
            init();
            isInit = true;
        }
        if (!isShow) {
            isShow = true;
            if (dialog != null) {
                dialog.show();
            }
        }
    }

    protected abstract View createView(Activity activity);

    protected abstract void initView(View view);


    private void init() {
        View view = createView(activity);
        dialog = new AlertDialog.Builder(activity, android.R.style.Theme_Translucent_NoTitleBar)
                .setView(view)
                .setCancelable(false)
                .create();
        initView(view);
    }

    @Override
    public void hide() {
        if (isShow) {
            isShow=false;
            if (dialog != null) {
                dialog.hide();
            }
        }
    }
}
